﻿using System.Collections.Generic;
using FoobarFootball.Models.MatchStates;

namespace FoobarFootball.Models
{
    public class MatchEngine
    {
        private MatchState state;
        public Football Ball { get; set; }
        public Pitch Pitch { get; set; }
        public Team HomeTeam { get; set; }
        public Team AwayTeam { get; set; }
        public Team AttackingTeam { get; set; }
        public Team DefendingTeam { get; set; }
        public List<string> Commentry { get; set; }

        public MatchEngine()
        {
            Commentry = new List<string>();
            
            // TODO: Load the teams
            HomeTeam = new Team();
            HomeTeam.Name = "Chelsea";
            HomeTeam.FirstTeam = new Squad();
            HomeTeam.MatchSquad = HomeTeam.FirstTeam;

            AwayTeam = new Team();
            AwayTeam.Name = "Leeds United";
            AwayTeam.FirstTeam = new Squad();
            AwayTeam.MatchSquad = AwayTeam.FirstTeam;

            AttackingTeam = AwayTeam;
            DefendingTeam = HomeTeam;

            Pitch = new Pitch();

            Ball = new Football();
            Ball.CurrentPosition = Pitch.Five;

            string competitionName = "FA Cup 5th round";
            string stadiumName = "Stamford Bridge";

            Commentry.Add("Match Starting");
            Commentry.Add(string.Format("Welcome to {0} for this {1} clash between {2} and {3}. I'm your host Liam Molloy. Lets hand you over to our match commentators...", stadiumName, competitionName, HomeTeam.Name, AwayTeam.Name));
            state = KickOff.Instance();
            state.Turn(this);
        }

        /// <summary>
        /// Allows a Match to change from one state to another
        /// </summary>
        /// <param name="to">The Match state to change to</param>
        public void ChangeState(MatchState to)
        {
            state = to;
            state.Turn(this);
        }
    }
}
